/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejercicios7_1y2;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import consola.Consola;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 *
 * @author Mañana
 */
public class Ejercicios7_1y2 {
    static String fichero = "./DOUBLE.bin";

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        
        escribir();
        leer();
        
    }
//Metodo de escribe Numeros en el archivo DOUBLE.boin
    private static void escribir() {
        try {
            File ficheroNombre = new File(fichero);
            FileOutputStream filein = new FileOutputStream(fichero);
            DataOutputStream dataOS = new DataOutputStream(filein);
            Scanner s=new Scanner(System.in);
            System.out.println("Introduzca un Numero:");
            while(s.hasNext()){
                System.out.println("Introduzca un Numero:");
                dataOS.writeDouble(s.nextDouble());
            }
            dataOS.close();
        }catch (Exception io){
            System.out.println("Error S/N");
        }
	
    }
    //Metodo que lee el Archivo DOUBLE.BIN
    private static void leer() throws FileNotFoundException, IOException {
      try{
      FileInputStream fileout = new FileInputStream(fichero);
      DataInputStream dataIS = new DataInputStream(fileout);
      double n;
      try{
          while(true){
              n=dataIS.readDouble();
              System.out.println("Numero: "+n);// Devuelve el Numero
          }
      }
      catch (EOFException eo){}
      finally{
          dataIS.close();}
    }
    catch (FileNotFoundException fnfe){
    System.out.println("El fichero no Existe");}
    catch (IOException ioe){
    System.out.println("Error de E/S");}
    }
}


